package com.shunda.ysdgj.manager.controller.goods;

import com.shunda.ysdgj.manager.service.goods.GoodsBrandCategoryService;
import com.shunda.ysdgj.model.dto.base.IdsDto;
import com.shunda.ysdgj.model.dto.goods.GoodsBrandCategoryFindDto;
import com.shunda.ysdgj.model.entity.goods.GoodsBrandCategory;
import com.shunda.ysdgj.model.vo.ResultVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "商品品牌分类接口")
@RestController
@RequestMapping("/api/v1/admin/goods/brandCategory")
@RequiredArgsConstructor
public class GoodsBrandCategoryController {

    private final GoodsBrandCategoryService goodsBrandCategoryService;

    @Operation(summary = "根据分类获取品牌")
    @GetMapping("brand/{categoryId}")
    public ResultVo brand(@PathVariable Long categoryId) {
        return ResultVo.success(goodsBrandCategoryService.findBrandByCategoryId(categoryId));
    }

    @Operation(summary = "根据品牌获取分类")
    @GetMapping("category/{brandId}")
    public ResultVo category(@PathVariable Long brandId) {
        return ResultVo.success(goodsBrandCategoryService.findByBrandId(brandId));
    }

    @Operation(summary = "分页获取品牌分类列表")
    @PostMapping("list")
    public ResultVo list(@RequestBody GoodsBrandCategoryFindDto goodsBrandCategoryFindDto) {
        return ResultVo.success(goodsBrandCategoryService.findByPage(goodsBrandCategoryFindDto));
    }

    @Operation(summary = "添加品牌分类")
    @PostMapping("add")
    public ResultVo add(@RequestBody GoodsBrandCategory goodsBrandCategory) {
        if (!goodsBrandCategoryService.add(goodsBrandCategory)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

    @Operation(summary = "修改品牌分类")
    @PostMapping("modify")
    public ResultVo modify(@RequestBody GoodsBrandCategory goodsBrandCategory) {
        if (!goodsBrandCategoryService.modify(goodsBrandCategory)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

    @Operation(summary = "删除品牌分类")
    @PostMapping("delete")
    public ResultVo delete(@RequestBody IdsDto idsDto) {
        if (!goodsBrandCategoryService.deleteByIds(idsDto)) {
            return ResultVo.fail();
        }
        return ResultVo.success();
    }

}
